package com.tbit.main.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * @author LMY
 * @create 2020-10-27 20:45
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DispatchConfig {
    /**
     * 运营区域id
     */
    private Integer accountId;
    /**
     * 调度时间
     */
    private Integer dispatchTime;
    /**
     * 调度距离
     */
    private Integer dispatchDistance;
    /**
     * 是否允许同站点
     */
    private Integer sameParkPoint;
    /**
     * 更新时间
     */
    private String updateTime;

    /**
     * 两个工单之间是否产生订单
     */
    private Integer ride;
    /**
     * 两个工单距离 米
     */
    private Integer rideDistance;
    /**
     * 两个工单间隔时间 分钟
     */
    private Integer logTime;
    /**
     * 小时产生订单 小时
     */
    private Integer rideTime;
    /**
     * 调度闲置时长 单位小时
     */
    private Integer dispatchLeave;
    /**
     * 0-满足全部  1-满足一个
     */
    private Integer conditionType;

    /**
     * 已选中条件的下标 根据页面对应
     * 0 - 闲置时长超过xx小时
     * 1 - 上次调度后产生有效订单
     * 2 - 上次调度后经过xx分钟
     * 3 - 上次调度后骑行xx米
     */
    private String checkedCondition;

    public DispatchConfig(Integer accountId) {
        this.accountId = accountId;
        this.dispatchTime = 0;
        this.dispatchDistance = 200;
        this.sameParkPoint = 0;
        this.rideTime = 0;
        this.ride = 0;
        this.rideDistance = 0;
        this.logTime = 0;
        this.dispatchLeave = 0;
        this.conditionType = 0;
        this.checkedCondition = "0,1,2,3";
    }

    public void nullToDefaultVal() {
        if (this.dispatchTime == null) {
            this.dispatchTime = 0;
        }
        if (this.dispatchDistance == null) {
            this.dispatchDistance = 200;
        }
        if (this.sameParkPoint == null) {
            this.sameParkPoint = 0;
        }
        if (this.rideTime == null) {
            this.rideTime = 0;
        }
        if (this.ride == null) {
            this.ride = 0;
        }
        if (this.rideDistance == null) {
            this.rideDistance = 0;
        }
        if (this.logTime == null) {
            this.logTime = 0;
        }
        if (this.dispatchLeave == null) {
            this.dispatchLeave = 0;
        }
        if (this.conditionType == null) {
            this.conditionType = 0;
        }
        if (StringUtils.isBlank(this.checkedCondition)) {
            this.checkedCondition = "0,1,2,3";
        }
    }

    /**
     * 判断是否只需满足一个条件
     *
     * @return boolean
     */
    public boolean matchOne() {
        return Objects.equals(this.conditionType, 1);
    }

}
